package com.sz.app.oss.api.logistics.base;

import com.sz.app.oss.constants.Permissions;
import com.sz.biz.app.web.BaseController;
import com.sz.biz.logistics.core.entity.ProductGroup;
import com.sz.biz.logistics.core.service.ProductGroupService;
import com.sz.biz.logistics.core.dto.AllProductGroupDto;
import com.sz.biz.logistics.core.dto.ProductGroupDto;
import com.sz.common.base.dto.ResultDto;
import com.sz.common.base.dto.TreeNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Function: ProductGroupController <br>
 * Author: penghui.zheng <br>
 * Date: 2017-05-11 09:40:00
 */
@RestController
@RequestMapping("/api/v1/biz/product/group")
@Api(description = " ", tags = "039、产品组管理")
public class ProductGroupController extends BaseController {
    //Logger logger = Logger.getLogger(this.getClass());
    @Autowired
    private ProductGroupService productGroupService;

    /**
     * 根据parentId查询产品组
     *
     * @throws Exception
     */
    @ApiOperation(value = "搜索产品组", notes = "搜索产品组<br>权限：" + Permissions.BIZ_MGT_BASE_PRODUCT_GROUP)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父id", dataType = "int", paramType = "query")})
    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public ResultDto findByParentId(@RequestParam(required = true, defaultValue = "0") int parentId) {
        List<ProductGroupDto> list = productGroupService.findByParentId(parentId);
        ResultDto dto = new ResultDto();
        dto.setData(list);
        return dto;
    }

    /**
     * 根据id查询产品组
     *
     * @throws Exception
     */
    @ApiOperation(value = "搜索产品组", notes = "搜索产品组<br>权限：" + Permissions.BIZ_MGT_BASE_PRODUCT_GROUP)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "int", paramType = "query")})
    @RequestMapping(value = "/all", method = {RequestMethod.GET})
    public ResultDto findById(@RequestParam(required = true, defaultValue = "0") int id) {
        AllProductGroupDto allProductGroupDto = productGroupService.findAllById(id);
        ResultDto dto = new ResultDto();
        dto.setData(allProductGroupDto);
        return dto;
    }

    /**
     * 所有产品组
     * @throws Exception
     */
    @ApiOperation(value = "所有产品组", notes = "所有产品组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "isShowAll", value = "是否显示所有（包含非公开产品组）", dataType = "boolean", defaultValue = "true", paramType = "query")})
    @RequestMapping(value = "/list", method = {RequestMethod.GET})
    public ResultDto findAll(@RequestParam(required = false) Integer parentId, @RequestParam(required = false, defaultValue = "true") Boolean isShowAll) {
        List<TreeNode> productGroups = productGroupService.findAll(parentId, isShowAll);
        ResultDto dto = new ResultDto();
        dto.setData(productGroups);
        return dto;
    }

    /**
     * 根据Id查询根节点类型
     *
     * @throws Exception
     */
    @ApiOperation(value = "查询根节点类型", notes = "查询根节点类型<br>权限：" + Permissions.BIZ_MGT_BASE_PRODUCT_GROUP)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "int", paramType = "query")})
    @RequestMapping(value = "/root", method = {RequestMethod.GET})
    public ResultDto findTypeById(@RequestParam(required = true) int id) {
        int type = productGroupService.findTypeById(id);
        ResultDto dto = new ResultDto();
        dto.setData(type);
        return dto;
    }
    
    /**
     * 查询运输类型
     *
     * @throws Exception
     */
    @ApiOperation(value = "查询运输类型", notes = "查询运输类型<br>权限：" + Permissions.BIZ_MGT_BASE_PRODUCT_GROUP)
    @ApiImplicitParams({})
    @RequestMapping(value = "/type", method = {RequestMethod.GET})
    public ResultDto findTransportType() {
    	 List<ProductGroupDto> list = productGroupService.findTransportType();
         ResultDto dto = new ResultDto();
         dto.setData(list);
         return dto;
    }
    @ApiOperation(value = "获取所有的子节点")
    @RequestMapping(value = "/querychilds",method = RequestMethod.GET)
    public ResultDto queryAllChilds(){
        List<ProductGroup> list = productGroupService.findAllChild();
        ResultDto dto = new ResultDto();
        dto.setData(list);
        return dto;
    }
}
